<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Title</title>
</head>
<body>
<div>
    <h1>微博首页</h1>
    <div v-if="isLogin">
        <h1>欢迎{{user.nickname}}回来</h1>
        <a href="/insert.html">发微博</a>
        <a href="javascript:void(0)" @click="logout()">退出登陆</a>
        <a href="/list.html">查看微博列表</a>
        <a :href="'/myList.html?id='+user.id">查看我的微博</a>
    </div>
    <div v-else>
        <a href="/reg.html">注册</a>
        <a href="/login.html">登陆</a>
    </div>
    <hr>
    <div v-for="weibo in arr">
        <a :href="'/detail.html?id='+weibo.id">
            <h3>{{weibo.nickname}}说了：{{weibo.content}}</h3>
        </a>
    </div>
</div>
</body>
<script src="https://cdn.bootcdn.net/ajax/libs/axios/0.21.1/axios.min.js"></script>
<script src="https://cdn.staticfile.org/vue/2.6.14/vue.min.js"></script>
<script>
  let v = new Vue({
    el:"body>div",
      data: {
          user: {},
          isLogin: false,
          arr: []
      },
    methods:{
        logout() {
            if (confirm("确认退出登陆吗？")) {
                axios.get("/logout").then(function () {
                    v.isLogin = false;
                })
            }
        }
    },
    created: function () {
        axios.get("/currentUser").then(function (response) {
            if (response.data == "") {
                v.isLogin = false;
            } else {
                v.isLogin = true;
                v.user = response.data;
            }
        })
        axios.get("/weibo/select").then(function (response) {
            v.arr = response.data;
        })
    }
  })
</script>
</html>